package com.zkingsoft.services.distribution.impl;

import com.zkingsoft.services.distribution.DistributionUserService;
import com.zkingsoft.pojo.PaginationVO;
import com.zkingsoft.model.distribution.DistributionUser;
import com.zkingsoft.dao.distribution.DistributionUserDao;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.zkingsoft.exception.GlobleException;
import com.zkingsoft.util.ModelUtils;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;

/**
 * This field was generated by Zking.software.Codegen.
 * @date 2017-06-16 15:22
 */
@Service("distributionUserService")
public class  DistributionUserServiceImpl implements    DistributionUserService  {

	
	@Autowired
	private DistributionUserDao distributionUserDao;
	
	
	@Override
	public int add(DistributionUser distributionUser){
		
		return distributionUserDao.insert(distributionUser);
		
	}
	
	@Override
	public int batchAdd(List<DistributionUser>  distributionUserList) {
		int num = 0;

		int c = 10000;
		int size = distributionUserList.size()/c + 1;
		for(int i=0; i<size; i++) {
			int begin = i*c;
			int end = (i+1)*c;
			end = end >= distributionUserList.size() ? distributionUserList.size() : end;
			List<DistributionUser> insertList = distributionUserList.subList(begin, end);
			num += distributionUserDao.batchInsert(insertList);
		}
		return num;
		
	}
	
	
   	
    @Override
	public int modifyByMap(DistributionUser oldDistributionUser
	,DistributionUser newDistributionUser){
	
		if (!ModelUtils.isModified(oldDistributionUser, newDistributionUser)) {
			return 1;
		}
		Map<String, Object> modifyMap=null;
		try {
			modifyMap = ModelUtils.comparePojo2Map(oldDistributionUser, newDistributionUser);
		} catch (Exception e) {
			throw new GlobleException("数据对比失败");
		}
		if (modifyMap.size() > 0) {
			modifyMap.put("userId", oldDistributionUser.getUserId());
			distributionUserDao.updateByMap(modifyMap);
		}
		return 1;
	}
	
	@Override
	public int modifyByModel(DistributionUser distributionUser){
	
		return distributionUserDao.updateByModel(distributionUser);
	
	}
	
	
	
	@Override
	public int remove(List<Long> list){
	
		return distributionUserDao.deleteByIds(list);
	
	}

	@Override
	public int removeById(Long userId){
	
		return distributionUserDao.deleteById(userId);
	
	}
	
	@Override
	public int removeByModel(DistributionUser distributionUser){
	
		return distributionUserDao.deleteByModel(distributionUser);
	
	}
	
	
	@Override
	public List<DistributionUser> findInPage(DistributionUser distributionUser,  PaginationVO pageVo){
	
		return distributionUserDao.selectInPage(distributionUser , pageVo);
	
	}
	
	@Override
	public List<DistributionUser> findByModel(DistributionUser distributionUser){
	
		return distributionUserDao.selectByModel(distributionUser);
	
	}
	
	@Override
	public int  findTotal(DistributionUser distributionUser){
	
		return distributionUserDao.selectTotalRecord(distributionUser);
	
	}
	
	@Override
	public DistributionUser  findById(Long userId){
	
		return distributionUserDao.selectById(userId);
	
	}

   	
	
	
}